Function FormCheck () As Integer
FormCheck = False
If Trim$(txtState.Text) = "" Then
MsgBox "State Code Must Be Filled In"
txtState.SetFocus
Exit Function ElseIf Trim$(txtCompany.Text) = "" Then
MsgBox "Company Name Must Be Filled In"
txtCompany.SetFocus
Exit Function End If
FormCheck = True
End Function
In the preceding FormCheck() function, the FormCheck = True line has been moved to the bottom of the function. The FormCheck = False line is set at the top of the function. If one of the tests fails and you need to exit the function, the FormCheck = True line never gets executed.
With . . . End With
Another construct that will come in handy is the With...End With statement. This statement allows you to set multiple properties for one object without specifying the object name over and over again. Take the following code as an example:
Instead of having to specify the form name, frmEmployee1, over and over again, you can use the following code. Double-click on the With...End With command button on Main.frm to see the following code:
Private Sub cmdWith_Click()
With frmEmployee1
.Top = 0